@import '../style/mixins/index';
@import '../style/theme/color';

:host {
  display: inline-block;
}

.devui-checkbox {
  position: relative;
  display: flex;
  display: -ms-flexbox;
  align-items: center;
  -ms-flex-align: center;
  height: 100%;
  margin: 0;

  .devui-checkbox-tick {
    position: absolute;

    .devui-tick {
      stroke: $white;
      stroke-dasharray: 50;
      stroke-width: 2;
      stroke-miterlimit: 10;
      fill: none;
      stroke-dashoffset: 50;
      opacity: 0;
      transform: scale(0);
      transform-origin: 50% 50%;
      transition: stroke-dashoffset .2s ease-in-out, opacity .2s ease-in-out, transform .2s ease-in-out;
    }
  }

  &.active:not(.halfchecked) .devui-tick {
    opacity: 1;
    stroke-dashoffset: 0;
    transform: scale(1);
    transition: stroke-dashoffset .3s cubic-bezier(0.755, 0.05, 0.855, 0.06),
    opacity .2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
  }

  &.active, &.halfchecked {
    .devui-checkbox-material:not(.custom-color) {
      border-color: $status-blue;
    }
  }

  &.active {
    .devui-checkbox-material {
      & > .devui-checkbox-bg {
        opacity: 1;
        transform: scale(1);
        transition: transform .2s ease-in-out;
      }
    }
  }

  &.unchecked {
    .devui-checkbox-material {
      & > .devui-checkbox-bg {
        transform: scale(0);
        transition: transform .15s cubic-bezier(0.755, 0.05, 0.855, 0.06), opacity .2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
      }
    }
  }

  &.halfchecked {
    .devui-checkbox-material {
      & > .devui-checkbox-bg {
        opacity: 1;
        transform: scale(.57);
        transition: transform .2s cubic-bezier(0.755, 0.05, 0.855, 0.06);
      }
    }
  }

  .devui-checkbox-material {
    height: 14px;
    width: 14px;
    position: relative;
    user-select: none;
    border: thin solid $gray1;
    border-radius: 1px;
    margin-right: 5px;
    vertical-align: text-top;

    & > .devui-checkbox-bg {
      display: inline-block;
      position: absolute;
      content: "";
      background-color: $status-blue;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      transform: scale(0);
      opacity: 0;
    }
  }

  &:not(.disabled) {
    .devui-checkbox-material:not(.custom-color) {
      &:hover {
        border: thin solid $hover-control;
        transition: border-color .2s ease-in-out;

        & > .devui-checkbox-bg {
          background-color: $hover-control;
        }
      }

      &:active, &:focus {
        border: thin solid $focus2;
        transition: border-color .2s ease-in-out;
      }

      // 激活状态深色
      &:active, &:focus, &:hover:active, &:hover:focus {
        & > .devui-checkbox-bg {
          background-color: $focus2;
        }
      }
    }
  }

  &-input {
    opacity: 0;
    position: absolute;
    margin: 0;
    z-index: -1;
    width: 0;
    height: 0;
    overflow: hidden;
    left: 0;
    pointer-events: none;
  }

  & label {
    display: inline-block;
    position: relative;
    font-weight: normal;
    line-height: 1;
    cursor: pointer;
    color: $dark1;
    margin: 0;

    span {
      display: inline-block;
      box-sizing: content-box;
    }
  }

  // 禁用状态透明色
  &.disabled {
    opacity: 0.3;

    label {
      cursor: not-allowed;
    }
  }
}

.devui-no-animation {
  transition: none !important;
}
